package com.yhyvr.console.service;


import com.lz.mybatis.jdbc.auto.dao.BoProxyMapper;
import com.lz.mybatis.jdbc.auto.dao.BoProxyMapper;
import com.lz.mybatis.jdbc.auto.model.*;
import com.lz.mybatis.jdbc.auto.model.BoProxy;
import com.lz.tool.ListUtils;
import com.lz.tool.MD5;
import com.yhyvr.console.model.login.LoginUserModel;
import com.yhyvr.console.model.login.ProxyExtentsLoginModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 * title:系统登录处理
 * </p>
 * <p>
 * description:
 * </p>
 * 
 * @author 2016 北京太阳花互动科技有限公司 All Rights Reserved.
 * @create zhangqin
 * @update
 * @version 1.0
 * @date 2016年3月18日
 */
@Service("loginProxyServiceImp")
public class LoginProxyServiceImp implements LoginService {

	@Resource
	private BoProxyMapper boProxyMapper;

	/**
	 * 获取登录
	 * @param user_name
	 * @param user_password
	 * @param login_type
	 * @return
	 */
	@Override
	public LoginUserModel getLoginUserModel(String user_name,
											String user_password, String login_type) {
		//查询用户表
		BoProxyExample boProxyExample = new BoProxyExample();

		boProxyExample.createCriteria().andBoProxyStateEqualTo(1).andBoProxyPhoneEqualTo(user_name).andBoProxyPasswordEqualTo(MD5.MD5Encode(user_password))
		;
		BoProxy boProxy= ListUtils.getFirst( boProxyMapper.selectByExample(boProxyExample));

		if(boProxy!=null){
			LoginUserModel loginUserModel=new LoginUserModel();
			loginUserModel.setEmail(boProxy.getBoProxyMail());
			loginUserModel.setPhone(boProxy.getBoProxyPhone());
			loginUserModel.setUser_id(boProxy.getBoProxyId());
			loginUserModel.setUser_name(boProxy.getBoProxyNickName());
			loginUserModel.setUser_pic("");
			loginUserModel.setUser_type(LoginUserModel.loginTypeApp);
			loginUserModel.setUserNickName(boProxy.getBoProxyNickName());
			ProxyExtentsLoginModel proxyExtentsLoginModel = new ProxyExtentsLoginModel();
			proxyExtentsLoginModel.setBoProxyType(boProxy.getBoProxyType());
			loginUserModel.setProxyExtentsLoginModel(proxyExtentsLoginModel);
			return loginUserModel;
			}else{
				return null;
			}
	
	}

}
